<!-- // *** ebowden2, jamatz: 02-26-2007: Created Test Cases to ensure that any given search string is properly tokenized. -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>ECMAUnit Tests</title>
    <script language="JavaScript" type="text/javascript" src="chrome://mylog/content/mylog.js"></script>
    <script language="JavaScript" type="text/javascript" src="chrome://mylog/content/mylog-datastorage.js"></script>
    <script language="JavaScript" type="text/javascript" src="chrome://mylog/content/mylogsidebar.js"></script>
    <script type="text/javascript" src="chrome://mylog/content/test/ecmaunit.js"> </script>
    <script language="JavaScript" type="text/javascript" src="chrome://mylog/content/mylog-utility.js"></script>
    <script type="text/javascript">
//<![CDATA[
       
        function TestSplitSearchString() {
            this.name = 'TestSplitSearchString';
            
            this.setUp = function() { };
            
            this.checkOrderedResults = function(correct_results, results) {
           
            	this.assertEquals(results.length, correct_results.length);
       			for (var i = 0; i < correct_results.length; i++) {
					counter = 0;
					this.assertTrue(results != null);
					if (results != null) {
						for (var j = 0; j<results.length; j++) {
							if (results[j] == correct_results[i]) {
								counter++ ;
							}
						}
					}
					this.assertEquals(counter, 1);
				}
            };
            
            this.testSplitSearchString1 = function() {
            	var counter = 0;
            	var testString = 'keyword1 "quoted keyword 1" keyword2';
            	var results = splitSearchString(testString);
            	var correct_results = new Array('keyword1', 'quoted keyword 1', 'keyword2');
            	this.checkOrderedResults(correct_results, results);
			};
			
			this.testSplitSearchString2 = function() {
            	var counter = 0;
            	var testString = 'keyword1 keyword2 keyword3';
            	var results = splitSearchString(testString);
            	var correct_results = new Array('keyword1', 'keyword2', 'keyword3');
            	this.checkOrderedResults(correct_results, results);
			};


			this.testSplitSearchString3 = function() {
            	var counter = 0;
            	var testString = '';
            	var results = splitSearchString(testString);
            	this.assertEquals(results.length, 0);
			};
			
			this.testSplitSearchString4 = function() {
            	var counter = 0;
            	var results = splitSearchString();
            	this.assertEquals(results, null); 	
			};


			this.testSplitSearchString5 = function() {
            	var counter = 0;
            	var testString = '"quoted keyword 1" "quoted keyword 2" "quotedkeyword 3"';
            	var results = splitSearchString(testString);
            	var correct_results = new Array("quoted keyword 1", "quoted keyword 2", "quotedkeyword 3");
            	this.checkOrderedResults(correct_results, results);
			};			
			
			this.testSplitSearchString6 = function() {
            	var counter = 0;
            	var testString = 'cheese -"cheese and crackers"';
            	var results = splitSearchString(testString);
            	var correct_results = new Array("cheese", "-cheese and crackers");
            	this.checkOrderedResults(correct_results, results);
			};
			
			this.testSplitSearchString7 = function() {
            	var counter = 0;
            	var testString = 'ham +"bacon and eggs"';
            	var results = splitSearchString(testString);
            	var correct_results = new Array("ham", "bacon and eggs");
            	this.checkOrderedResults(correct_results, results);
			};
			
			this.testSplitSearchString8 = function() {
            	var counter = 0;
            	var testString = '  + - +-          +      ---  ';
            	var results = splitSearchString(testString);
            	this.assertEquals(results.length, 0);
			};

			this.testSplitSearchString9 = function() {
            	var counter = 0;
            	var testString = '   spaces before and after search terms';
            	var results = splitSearchString(testString);
            	var correct_results = new Array("spaces", "before", "and", "after", "search", "terms");
            	this.checkOrderedResults(correct_results, results);
			};
			
			this.testSplitSearchString10 = function() {
            	var counter = 0;
            	var testString = null;
            	var results = splitSearchString(testString);
            	this.assertEquals(results, null);
			};

			this.tearDown = function() {
            
            };
        };
        
        this.testSplitSearchString11 = function() {
           	var counter = 0;
           	var testString = 'cheese -------------"cheese and crackers"';
           	var results = splitSearchString(testString);
           	var correct_results = new Array("cheese", "-cheese and crackers");
           	this.checkOrderedResults(correct_results, results);
		};
       
        
        TestSplitSearchString.prototype = new TestCase;

        function runTests() {
            placeholder = document.getElementById('placeholder');
            var testsuite = new TestSuite(new HTMLReporter(placeholder));
            testsuite.registerTest(TestSplitSearchString);
            testsuite.runSuite();
        }
//]]>
</script>
</head>

<body onload="runTests()">
<h3>EcmaUnit tests for Splitting Search Strings</h3>
<div id="placeholder"> </div>
</body>
</html>
